package com.internal.Internalhibernate.server.dao;

// Generated Dec 30, 2011 7:25:21 AM by Hibernate Tools 3.4.0.CR1

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.internal.Internalhibernate.client.AdmSemester;
import com.internal.Internalhibernate.server.SessionFactoryUtil;

/**
 * Home object for domain model class AdmSemester.
 * 
 * @see com.internal.Internalhibernate.client.AdmSemester
 * @authocom.internal.Internalhibernate.clientate Tools
 */
public class AdmSemesterDAO {

	private static final Log log = LogFactory.getLog(AdmSemesterDAO.class);

	private final SessionFactory sessionFactory = SessionFactoryUtil
			.getSessionFactory();

	public void persist(AdmSemester transientInstance) {
		log.debug("persisting AdmSemester instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.persist(transientInstance);
			trans.commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(AdmSemester instance) {
		log.debug("attaching dirty AdmSemester instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.saveOrUpdate(instance);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AdmSemester instance) {
		log.debug("attaching clean AdmSemester instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.lock(instance, LockMode.NONE);
			trans.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(AdmSemester persistentInstance) {
		log.debug("deleting AdmSemester instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			session.delete(persistentInstance);
			trans.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("delete failed", re);
			throw re;
		}
	}

	public AdmSemester merge(AdmSemester detachedInstance) {
		log.debug("merging AdmSemester instance");
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			AdmSemester result = (AdmSemester) session.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			trans.rollback();
			log.error("merge failed", re);
			throw re;
		}
	}

	public AdmSemester findById(byte id) {
		log.debug("getting AdmSemester instance with id: " + id);
		Transaction trans = null;
		try {
			Session session = sessionFactory.getCurrentSession();
			trans = session.beginTransaction();
			AdmSemester instance = (AdmSemester) session.get(
					"com.internal.Internalhibernate.client.AdmSemester", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findAll() {
		List result = null;
		Transaction trans = null;
		Session session = sessionFactory.getCurrentSession();
		trans = session.beginTransaction();
		Query q = session.createQuery("from AdmSemester");
		result = q.list();
		return result;
	}
}
